package org.noote.libs.sogle;

import javax.microedition.khronos.opengles.GL10;

public class Light {

	protected boolean isActive = false;
	
	protected float lightPosition[] = {0, 0, 1, 0.0f};
    
	protected float lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f};
	protected float lightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
	protected float lightSpecular[] = {1.0f, 1.0f, 1.0f, 1.0f};
    
    public void enable(boolean bEnable) {
    	isActive = bEnable;
    }
    
    public void setAmbient(float red, float green, float blue)
	{
		setAmbient(red, green, blue, 1);
	}
	public void setAmbient(float red, float green, float blue, float alpha)
	{
		lightAmbient[0] = red;
		lightAmbient[1] = green;
		lightAmbient[2] = blue;
		lightAmbient[3] = alpha;
	}
	public void noAmbient()
	{
		setAmbient(0, 0, 0, 1);
	}
	
	public void setDiffuse(float red, float green, float blue)
	{
		setDiffuse(red, green, blue, 1);
	}
	public void setDiffuse(float red, float green, float blue, float alpha)
	{
		lightDiffuse[0] = red;
		lightDiffuse[1] = green;
		lightDiffuse[2] = blue;
		lightDiffuse[3] = alpha;
	}
	
	public void setSpecular( float red, float green, float blue)
	{
		setSpecular(red, green, blue, 1);
	}
	public void setSpecular(float red, float green, float blue, float alpha)
	{
		lightSpecular[0] = red;
		lightSpecular[1] = green;
		lightSpecular[2] = blue;
		lightSpecular[3] = alpha;
	}
	public void noSpecular()
	{
		setSpecular(0, 0, 0, 1);
	}

	public void setPosition(float px, float py, float pz)
	{
		lightPosition[0]=px;
		lightPosition[1]=py;
		lightPosition[2]=pz;
		lightPosition[3]=1.0f;
	}
	
	public void setDirection(float px, float py, float pz)
	{
		lightPosition[0]=px;
		lightPosition[1]=py;
		lightPosition[2]=pz;
		lightPosition[3]=0.0f;
	}

	public void draw(GL10 gl, int iLight)
	{
		if(!isActive)
		{
			gl.glDisable(iLight);
			return;
		}
        
        gl.glLightfv(iLight, GL10.GL_AMBIENT, lightAmbient, 0);
        gl.glLightfv(iLight, GL10.GL_DIFFUSE, lightDiffuse, 0);
        gl.glLightfv(iLight, GL10.GL_SPECULAR, lightSpecular, 0);
        
        gl.glLightfv(iLight, GL10.GL_POSITION, lightPosition, 0);
        
    	gl.glEnable(iLight);
	}
}
